<template>
  <div>
    <Layout />
    <el-form class="auto-generate-form" ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item prop="typesNum[1]" label="单选题:">
        <el-input-number v-model="form.typesNum[1]" :min="0"></el-input-number>
      </el-form-item>
      <el-form-item prop="typesNum[2]" label="填空题:">
        <el-input-number v-model="form.typesNum[2]" :min="0" label="填空题:"></el-input-number>
      </el-form-item>
      <el-form-item prop="typesNum[3]" label="简答题:">
        <el-input-number v-model="form.typesNum[3]" :min="0" label="简答题:"></el-input-number>
      </el-form-item>
      <el-form-item prop="difficulty" label="难度:">
        <el-input-number v-model="form.difficulty" :min="1" :max="10" label="难度:"></el-input-number>
      </el-form-item>
      <el-form-item prop="score" label="总分:">
        <el-input-number v-model="form.score" :min="1" :max="100" label="总分:"></el-input-number>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import Layout from '@/layout'
import { autoGenerate ,getAllPapers } from '@/api/autoGenerate'
export default {
  name: 'autoGenerate',
  components: { Layout },
  data() {
    return {
      form: {
        score: undefined,
        typesNum: {
          1: undefined,
          2: undefined,
          3: undefined
        },
        difficulty: undefined
      },
      // 表单校验
      rules: {
        'typesNum[1]': [
          { required: true, message: "题目数量不能为空", trigger: "blur" },
        ],
        'typesNum[2]': [
          { required: true, message: "题目数量不能为空", trigger: "blur" },
        ],
        'typesNum[3]': [
          { required: true, message: "题目数量不能为空", trigger: "blur" },
        ],
        difficulty: [
          { required: true, message: "难度不能为空", trigger: "blur" },
        ],
        score: [
          { required: true, message: "总分不能为空", trigger: "blur" },
        ],
        // age: [{ required: true, message: "学生年龄不能为空", trigger: "blur" }],
      },
    };
  },
  methods: {
    onSubmit() {
      let _this = this
      console.log(autoGenerate)
      autoGenerate(this.form)
        .then((re) => {
          console.log(re)
          if (re.success) {
            _this.$alert( re.message , {
              confirmButtonText: "返回首页",
              callback: (action) => {
                _this.$router.push("/paper");
              },
            });
          } else {
            _this.$message.error(re.message);
          }
        })
        .catch((e) => {
          _this.$message.error(re.message);
        });
    }
  },
}
</script>

<style lang="scss" scoped>
.auto-generate-form {
  padding-top: 50px;
  padding-right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
</style>
